from typing import Optional
from pydantic import BaseModel
from uuid import UUID
from datetime import datetime


class FileAssetBase(BaseModel):
    storage_key: str
    url: str
    original_name: str
    ext: Optional[str] = None
    mime_type: str
    size_bytes: int
    checksum_sha256: str
    etag: Optional[str] = None
    bucket: Optional[str] = None
    storage_provider: str = 'nginx-webdav'
    visibility: str = 'public'
    owner_id: Optional[str] = None
    uploader_id: Optional[UUID] = None
    expires_at: Optional[datetime] = None


class FileAssetCreate(FileAssetBase):
    pass


class FileMediaInfo(BaseModel):
    width: Optional[int] = None
    height: Optional[int] = None
    duration_ms: Optional[int] = None
    thumbnails_json: Optional[str] = None
    codec: Optional[str] = None
    orientation: Optional[str] = None
    dpi: Optional[int] = None


class FileAssetRead(FileAssetBase):
    id: UUID
    is_deleted: bool | None = False
    created_at: datetime | None = None
    updated_at: datetime | None = None
    media_info: Optional[FileMediaInfo] = None

    class Config:
        from_attributes = True


class FileBindPayload(BaseModel):
    file_id: UUID
    role: Optional[str] = None
